<?php

/*
  This model provides all interfaces for user management
 */

class User_model extends CI_Model {

  

    public function getDetails() {

        $id = $this->session->userdata('id');
        $this->db->select("users.email");
        $this->db->select("users.usertype");
        $this->db->select("users_data.*");
        $this->db->from("users");
        $this->db->join("users_data", "users_data.user_id = users.id");
        $this->db->where("users_data.user_id", $id);
        $query = $this->db->get();
        return $query->result();
    }
    
    public function getUserFranchiseID() {

        $id = $this->session->userdata('id');
        $this->db->select("users.franchise_id");      
        $this->db->from("users");       
        $this->db->where("users.id", $id);
        $query = $this->db->get();
        $rs = $query->result();
        if(isset($rs[0]))
            return $rs[0]->franchise_id;
        else return -1;
    }

    public function getUserByFranchiseId($id = null) {
        $this->db->select("users.email");
        $this->db->select("users.usertype");
        $this->db->select("users_data.*");
        $this->db->from("users");
        $this->db->join("users_data", "users_data.user_id = users.id");
        if ($id) {
            $this->db->where("users.franchise_id", $id);
        }
        $this->db->where("users.usertype !=", 'Administrator');
        $this->db->where("users.usertype !=", 'FranchiseManager');
        
        
        $query = $this->db->get();
        
        return $query->result();
    }

    public function getFranchise() {
        $this->db->select("*");
        $this->db->from("franchise");
        $this->db->where("status", '1');
        $query = $this->db->get();
        $franchise[0] = 'Select Franchise';
        foreach ($query->result() as $rs) {
            $franchise[$rs->id] = $rs->name;
        }
        return $franchise;
    }

   
}